
layui.use(["form","layer"],function () {

	var form = layui.form;
	var layer = layui.layer;
	/**
	 * 新增课程
	 */
	$("#bt_addCourse").click(function(){
		var id=$("#id").val();
		var name=$("#name").val();
		var college=$("#college").val();
		var major=$("#major").val();
		var property=$("input[name='property']:checked").val();
		var credit=$("#credit").val();
		var teacherId=$("#teacherId").val();
		var state=$("input[name='state']:checked").val();
		var restrictedNum=$("#restrictedNum").val();
		var cycle=$("#cycle").val();
		//处理switch控件关闭状态,避免undefined,向后台传null
		if(state==null){
			state="false";
		}
		if(id==""||name==""||college==""||major==""||property==""||credit==""||teacherId==""||restrictedNum==""||cycle==""){
			//alert("有输入项未输入");
		}
		else{
			$.ajax({
				url:"addCourse",
				post:"get",
				async:"false",
				data:{
					"id":id,
					"name":name,
					"college":college,
					"major":major,
					"property":property,
					"credit":credit,
					"teacherId":teacherId,
					"state":state,
					"restrictedNum":restrictedNum,
					"cycle":cycle,
				},
				success:function(data){
					if(1==data){
						layer.msg("添加成功");
					}
					if(0==data){
						layer.msg("信息重复,添加失败");
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					layer.msg("系统繁忙,请稍后重试!");
				}
			});
		}
	});
});